# import image12
# image = image12.Imagedata12
#
LCD_WIDTH = 170
LCD_HEIGHT = 320
image_num = 0
Path = 'C:/Users/yangy/Desktop/TFTLCD/image/'
#
#
# size = LCD_WIDTH * LCD_HEIGHT *2
# block = LCD_WIDTH * 2
# lines = size // block
#
# for v in range(0, lines+1):
#     if v == lines:
#         buf = image[(v * block):]
#     else:
#         buf = image[(v * block):(v + 1) * block]
#     print(v, '\n', buf)

def image_data_save(data):
    global image_num
    line = 340
    length = LCD_HEIGHT*LCD_WIDTH*2
    if len(data) == length:
        image_num += 1
        print(image_num)
    else:
        print('数据读取错误！！！')
    txt_name = Path + 'image' + str(image_num) + '.py'
    list_name = 'Imagedata' + str(image_num) + ' = ' + '['
    file = open(txt_name, 'w')
    print(length, len(data))
    for v in range(-1, length+1):
        if v == -1:
            file.write(list_name+'\n')
        elif (v+1) % line == 0:
            file.write(data[v] + ',' + '\n')
        elif v == length:
            file.write(']')
        elif v != length-1:
            file.write(data[v] + ',')
    file.flush()
    file.close()


if __name__ == '__main__':
    data = []
    for i in range(170*320*2):
        data.append(str(hex(i)))
    image_data_save(data)
